#include <iostream>
#include <opencv2\opencv.hpp>

using namespace cv;

int main()
{
    //设置原始点位数据
    std::vector<cv::Point2d> p1s, p2s;
    p1s.push_back(cv::Point2d(1224.5, 1024));
    p1s.push_back(cv::Point2d(2109.8, 1013.9));
    p1s.push_back(cv::Point2d(2141.5, 387.3));
    p1s.push_back(cv::Point2d(1254.1, 396));
    p1s.push_back(cv::Point2d(352.6, 409));
    p1s.push_back(cv::Point2d(359.4, 1019.5));
    p1s.push_back(cv::Point2d(370.4, 1741));
    p1s.push_back(cv::Point2d(1262.3, 1732.7));
    p1s.push_back(cv::Point2d(2077, 1716.5));
    p2s.push_back(cv::Point2d(335.876, -308.875));
    p2s.push_back(cv::Point2d(335.876, -294.475));
    p2s.push_back(cv::Point2d(325.604, -293.775));
    p2s.push_back(cv::Point2d(325.604, -308.275));
    p2s.push_back(cv::Point2d(325.604, -322.975));
    p2s.push_back(cv::Point2d(335.604, -322.975));
    p2s.push_back(cv::Point2d(347.404, -322.975));
    p2s.push_back(cv::Point2d(347.404, -308.475));
    p2s.push_back(cv::Point2d(347.404, -295.125));

    //测试点位
    Point2d src(64, 32);

    //利用estimateAffine2D计算标定矩阵
    Mat transEstimate = cv::estimateAffine2D(p1s, p2s);
    std::cout << transEstimate << std::endl;

    //计算标定结果
    Point2d dst;
    dst.x = transEstimate.at<double>(0) * src.x + transEstimate.at<double>(1) * src.y + transEstimate.at<double>(2);
    dst.y = transEstimate.at<double>(3) * src.x + transEstimate.at<double>(4) * src.y + transEstimate.at<double>(5);
    std::cout << dst << std::endl;

    //利用estimateAffinePartial2D计算标定矩阵
    transEstimate = cv::estimateAffinePartial2D(p1s, p2s);
    std::cout << transEstimate << std::endl;

    //计算标定结果
    dst.x = transEstimate.at<double>(0) * src.x + transEstimate.at<double>(1) * src.y + transEstimate.at<double>(2);
    dst.y = transEstimate.at<double>(3) * src.x + transEstimate.at<double>(4) * src.y + transEstimate.at<double>(5);
    std::cout << dst << std::endl;

}

